package com.kitty.game.player.serializer;

import com.kitty.game.role.model.Role;
import com.kitty.game.equip.model.EquipBox;
import com.kitty.game.utils.JsonUtils;
import com.kitty.game.utils.ZipUtil;
import org.apache.commons.lang3.StringUtils;

public class EquipBoxSerializer implements IPlayerPropSerializer {

    @Override
    public void serialize(Role player) {
        if (player.getEquipBox() != null) {
            String equipBoxJson = JsonUtils.object2String(player.getEquipBox());
            player.setEquipBoxJson(ZipUtil.compress(equipBoxJson));
        }
    }

    @Override
    public void deserialize(Role player) {
        String json = player.getEquipBoxJson();
        if (StringUtils.isNotEmpty(json)) {
            String content =ZipUtil.uncompress(json);

            player.setEquipBox(JsonUtils.string2Object(content, EquipBox.class));
        }
    }
}
